<?php
/*  psnClan 0.9.2
 
    Copyright (C) 2011  Vespo Marco | http://thelairofthemad.altervista.org/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

-----------------------------------------------------------------------------------------------*/
include_once 'psnFriends.class.php';
include_once 'player.class.php';

class psnClan extends psnFriends{

	private $friends;
	
	function __construct($sessionId){
		parent::__construct($sessionId);				
	}
	
	private function loadTrophiesFriendsFromXml(){
		if(isset($this->xml)){
			$friends=array();
			$i=0;
			foreach($this->xml->psn_friend as $friend)
				$friends[$i++]=new player($friend->onlineid,new trophies($friend->trophy->level,(int)$friend->trophy->bronze,(int)$friend->trophy->silver,(int)$friend->trophy->gold,(int)$friend->trophy->platinum),'https://secure.eu.playstation.com'.$friend->current_avatar);
			return $this->friends=$friends;
		}
		return 0;
	
	}
		
	public function loadRankingTrophies(){	
		$friends=$this->loadTrophiesFriendsFromXml();
		usort ( $friends,array('player','cmpLevel'));			
		return $this->friends=$friends;	
	}
	
	public function echoTrophiesFriends(){
		if(!isset($this->friends))
			$this->loadTrophiesFriendsFromXml();		
		foreach($this->friends as $friend)
			echo $friend."<br>";		
	}
	
	public function getFriends(){if(isset($this->friends))return $this->friends;}	
}
?>
